package cc.linker.steplink.crm.merchant.util;

import java.io.*;

public class FileUtil {

	public static void copyFile(File src, String destPath) {

		InputStream is = null;
		OutputStream os = null;

		try {
			is = new FileInputStream(src);
			os = new FileOutputStream(new File(destPath));

			byte[] buffer = new byte[512];
			int length = 0;
			while ((length = is.read(buffer)) > 0) {
				os.write(buffer, 0, length);
			}

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {

			e.printStackTrace();
		} finally {
			try {
				is.close();
				os.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
    /** *//**保存文件 
     * @param stream 
     * @param path 
     * @param filename 
     * @throws IOException 
     */ 
    public static void SaveFileFromInputStream(InputStream stream, String path, String filename) throws IOException 
    {
        FileOutputStream fs=new FileOutputStream( path +"\\"+ filename); 
        byte[] buffer =new byte[1024*1024]; 
        @SuppressWarnings("unused")
		int bytesum = 0; 
        int byteread = 0; 
        while ((byteread=stream.read(buffer))!=-1) 
        { 
           bytesum+=byteread; 
           fs.write(buffer,0,byteread); 
           fs.flush(); 
        } 
        fs.close(); 
        stream.close();      
    }       

	

}
